/**
  * @(#)UniversityProfile.java
  *
  * The UniversityProfile class contains the implementation which stores
  * 	and controls access to the configuration files for the University.
  *
  * @author Course Scheduler Team
  * 
  * @license GNU General Public License version 3 (GPLv3)
  *
  * This file is part of Course Scheduler, an open source, cross platform
  * course scheduling tool, configurable for most universities.
  *
  * Copyright (C) 2010-2012 Course Scheduler Team
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * 
  */
package com.pollicitus.scheduler.profiles;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.pollicitus.scheduler.model.TermFactory;
import com.pollicitus.scheduler.profiles.RetrievalProfile;

/**
 * University profile class which abstracts the storage of university related 
 *		settings and configurations
 *
 * @author Course Scheduler Team
 *
 */
public abstract class UniversityProfile extends Profile {

	/**
	 * The most recent revision in which this file was changed in the source control system
	 */
	public static final String _revision = "$LastChangedRevision: 539 $";
	
	/**
	 * The date on which this file was last changed and submitted to source control
	 */
	public static final String _date = "$LastChangedDate: 2011-11-19 23:14:16 -0500 (Sat, 19 Nov 2011) $";
	
	/**
	 * The user which last changed the file and committed the change to source control
	 */
	public static final String _author = "$LastChangedBy: mike@pollicitus.com $";
	
	/**
	 * The URL which can be used to access this specific file within the source control system
	 */
	public static final String _headURL = "$HeadURL: https://courseschedulerx.googlecode.com/svn/trunk/course-scheduler/course-scheduler-core/src/main/java/com/pollicitus/scheduler/profiles/UniversityProfile.java $";
	
	/**
	 * The source control file ID, comprised of the file name, latest revision, last changed date, and submitting user.
	 */
	public static final String _id = "$Id: UniversityProfile.java 539 2011-11-20 04:14:16Z mike@pollicitus.com $";
	
	//private namespace identifiers
	private static final String universityNamespaceIdentifier = "university";
	
	//uParms specfic properties
	//private static final String uUniversityProfilesDir = gProfilesDir + "university/";
	private static final String uTermCodeExtensionProp = ".code";
	private static final String uTermNameExtensionProp = ".name";
	private static final String uTermFormatExtensionProp = ".format";
	private static final String uTermPrefixProp = "term";
	private static final String uTermListProp = uTermPrefixProp + ".list";
	private static final String uTermFormatProp = uTermPrefixProp + uTermFormatExtensionProp;
	private static final String uTermYearFormatProp = uTermPrefixProp + ".year" + uTermFormatExtensionProp; 
	private static final String uCourseRetrievalListProp = "profile.retrieval.course.list";
	
	//map containing the different retrieval profiles with their names as keys
	private Map<String, RetrievalProfile> courseRetrievalProfs;
	
	/**
	 * Empty default constructor
	 */
	protected UniversityProfile() {}
	
	/**
	 * @param name
	 * @throws FileNotFoundException
	 * @throws IOException
	 */
	public UniversityProfile(String name) throws FileNotFoundException, IOException {
		/*this.name = name;
		
		Properties uParms;
		uParms = new Properties();
		
		uParms.load(new FileInputStream(uUniversityProfilesDir + name + gProfileExtensionProp));
		parms.put(universityNamespaceIdentifier, uParms);
		
		courseRetrievalProfs = initCourseRetrievalProfs();*/
	}
	
	/**
	 * @return a map containing the different retrieval profiles available for the university
	 */
	protected Map<String, RetrievalProfile> initCourseRetrievalProfs(){
		Map<String, RetrievalProfile> map = new HashMap<String, RetrievalProfile>();
		
		String[] profs = getRetrievalProfileList();
		
		for(String prof: profs) {
			/*try {
				map.put(prof, new RetrievalProfile(prof, parms.get(universityNamespaceIdentifier)));
			} catch(FileNotFoundException e) {
			} catch(IOException e) {
			}	*/
		}
		
		return map;
	}
		
	/**
	 * @return a list of available retrieval profiles for this university
	 * 		these may represent different methods of downloading the same
	 * 		course set or could be using the same download methods for
	 * 		different course sets
	 */
	public abstract String[] getRetrievalProfileList();/* {
		return getPropertyArray(prependNamespace(universityNamespaceIdentifier, 
				uCourseRetrievalListProp));
	}*/
	
	/**
	 * @return the list of available terms (not year specific)
	 * 		eg. Winter, Fall, Spring, Summer
	 */
	public abstract String[] getUniversityTermList(); /* {
		return getPropertyArray(prependNamespace(universityNamespaceIdentifier, 
				uTermListProp));
	}*/
	
	/**
	 * @param term
	 * @return the term code corresponding to the specified term
	 */
	public abstract String getTermCode(String term); /* {
		return getProperty(prependNamespace(universityNamespaceIdentifier, 
				uTermPrefixProp + "." + term + uTermCodeExtensionProp));
	}*/
	
	public abstract String getTermName(String term); /* {
		return getProperty(prependNamespace(universityNamespaceIdentifier, 
				uTermPrefixProp + "." + term + uTermNameExtensionProp));
	}*/
	
	/**
	 * @return get the term parameter format
	 */
	public abstract String getTermParmFormat(); /* {
		return getProperty(prependNamespace(universityNamespaceIdentifier, uTermFormatProp));
	}*/
	
	/**
	 * @return the year format for the university term property
	 */
	public abstract String getYearParmFormat(); /* {
		return getProperty(prependNamespace(universityNamespaceIdentifier, uTermYearFormatProp));
	}*/
	
	/**
	 * @return the list of available terms for the university
	 */
	public abstract List<String> getAvailableTerms(); /*{
		return new TermFactory(this).getAvailableTerms();
	}*/

	/**
	 * @param name
	 * @return the specified retrieval profile
	 */
	public RetrievalProfile getRetrievalProfile(String name) {
		return courseRetrievalProfs.get(name);
	}
	
	/**
	 * @return list of available university profiles
	 */
	public static List<String> getAvailableUniversityProfiles(){
		List<String> names = new ArrayList<String>();
		
		//add all the profiles into the list
		/*for(String name: new File(uUniversityProfilesDir).list()){
			if(name.endsWith(gProfileExtensionProp)){
				names.add(name.substring(0, name.length()-gProfileExtensionProp.length()));
			}
		}*/
		return names;
	}
}
